<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>盘点</title>
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <link rel="stylesheet" href="/lib/layui/layui/css/common.css">
    <script src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="../../js/jquery/jquery-1.9.1.js"></script>
    <script src="../../js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/lib/layui/layui/global.js"></script>
    <script src="/lib/layui/layui/js/common.js?v=20190726" type="text/javascript" charset="utf-8"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
        }

        .layui-form .one{
            width: 100%;
            display: flex;
            flex-flow: row wrap;
            justify-content: space-around;
        }
        .layui-form-item{
            width: 48%;
        }

        .layui-form-label{
            width:64px;
        }
        .layui-input-block{
            margin-left: 140px;
            width: 240px;
        }
        select{
            width: 100%;
            height: 38px;
        }
        input::-webkit-input-placeholder {
            color: #aab2bd;
        }

        .buttonbottom button{
            background-color: #009284;
            width: 90px;
            margin-top: 30px;
        }
        .layui-treeSelect .ztree li span.button.root_open:before, .layui-treeSelect .ztree li span.button.root_close:before{
            content: "\e623";
        }
        .layui-form-label{
            width: 100px;
        }

        .disable{
            pointer-events: none;
            cursor: default;
            opacity: 0.6;
        }

    </style>
</head>
<body>
<div class="mbox">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" lay-filter="formTest" action=""style="width: 100%;margin: 0 auto;">
                <div style="width: 100%;height:36px;line-height:36px;font-weight:bold;padding-left: 6px;background-color: #eeeeee">基本信息</div>
                <div class="one" style="padding-top: 10px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: 100px;">设备名称</label>
                        <div class="layui-input-block" style="width: 240px;">
                            <input type="text" id="equipName" name="equipName" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item ">
                        <label class="layui-form-label"><span style="color: red;">*</span>设备编码</label>
                        <div class="layui-input-block equipNoYn">
                            <input type="text" id="equipNo" name="equipNo" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one" style="padding-top: 10px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: 100px;">规格型号</label>
                        <div class="layui-input-block modelNoYn" style="width: 240px;">
                            <input type="text" id="modelNo" name="modelNo" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>出厂编号</label>
                        <div class="layui-input-block factoryNoYn">
                            <input type="text" id="factoryNo" name="factoryNo" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one" style="padding-top: 10px;">
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">使用部门</label>
                        <div class="layui-input-block deptIdYn" style="width: 240px;" id="deptoper">
                            <select name="deptId" style="" id="deptId" lay-filter="selectdept" >
                                <option></option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">设备位置</label>
                        <div class="layui-input-block positionIdYn" id="ctreediv">
                            <input type="text" id="ctree" lay-filter="ctree" class="layui-input aaa">
                            <input id="positionId" name="positionId" type="hidden">
                        </div>
                    </div>
                </div>
                <div class="one" style="padding-top: 10px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: 100px;">生产厂家</label>
                        <div class="layui-input-block manufacturerYn" style="width: 240px;">
                            <input type="text" id="manufacturer" name="manufacturer" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>供应商</label>
                        <div class="layui-input-block supplierYn">
                            <input type="text" id="supplier" name="supplier" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="one" style="padding-top: 10px;">
                    <div class="layui-form-item">
                        <label class="layui-form-label" style="width: 100px;">资产原值</label>
                        <div class="layui-input-block assetsCostYn" style="width: 240px;">
                            <input type="text" id="assetsCost" name="assetsCost" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span style="color: red;">*</span>资产状态</label>
                        <div class="layui-input-block equipStatuasCodeYn" id="zicdiv">
                            <select name="equipStatuasCode" id="equipStatuasCode" style="">
                                <option></option>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="one" style="padding-top: 10px;">
                    <div class="layui-form-item" style="width: 98%">
                        <label class="layui-form-label"><span style="color: red;">*</span>盘点备注</label>
                        <div class="layui-input-block">
                            <input type="text" id="memo" name="memo" placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button type="button" class="layui-btn layui-btn-sm" lay-event="add" id="add" style="width: 70px">选择设备</button>
        <button type="button" class="layui-btn layui-btn-sm" lay-event="del" style="width: 70px">删除</button>
    </div>
</script>
<script>
    // 获取地址栏参数值
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
    var detailId = getQueryString("detailId");
    var inveId = getQueryString("inveId");
    var checkobj = parent.checkobj;
    var status = getQueryString("status");
    var contId;
    var objdata
    $('.layui-input-block').addClass('disable');

    layui.use(['form','table', 'laydate','element','treeSelect'], function() {
        var form = layui.form
            , layer = layui.layer
            , laydate = layui.laydate
            , form = layui.form
            , table = layui.table
            , $ = layui.jquery
            , treeSelect = layui.treeSelect;
        if(status == 1){
            for(var key in checkobj){
                if(checkobj[key] == "1"||checkobj[key] == 1){
                    $('.'+key).removeClass('disable')
                }
            }
            layui.form.render()
        }
            $.ajax({
                type: "post",
                url: "/equipInventory/findInvenByDetailId",
                dataType: "json",
                data: {
                    detailId:detailId
                },
                success: function (res) {

                    objdata = res.obj;
                    form.val("formTest",objdata);
                    ctree(objdata.positionId,objdata.deptId);

                    //原部门所属组织下拉框
                    $.ajax({
                        type: 'get',
                        url: '/equipTransfer/userDept',
                        dataType: 'json',
                        success: function (data) {
                            var render = [];
                            var deptdata = data.data;
                            var userName = data.object.userName;
                            var userId = data.object.userId;
                            for (var i = 0; i < deptdata.length; i++) {
                                render.push("<option class='' value=\"" + deptdata[i].deptId + "\">" + deptdata[i].deptName + "</option>");
                            }
                            $("#deptId").html(render.join(""));
                            $('#deptId').find('option[value="'+objdata.deptId+'"]').prop('selected',true);
                            // ctree(null,objdata.deptId);
                            form.render();
                            // $("#checkUser").val(userName);
                            // $("#checkUser").attr("data-id",userId);
                            // $("#checkUser").attr("disabled",true);
                        }
                    });


                    $.ajax({
                        type: 'get',
                        url: '/equipCapy/selectCommonCode',
                        dataType: 'json',
                        data: {
                            parentTypeNo:'EQUIP_STATUAS',
                        },
                        success: function (data) {
                            var selectArray2=data[0]; //分别定义六个选择
                            var $select1=$("select[name='equipStatuasCode']");
                            var optionStr='';
                            for(var i=0;i<selectArray2.length;i++){
                                var select1option=selectArray2[i];
                                optionStr+='<option value="'+select1option.codeTypeNo+'">'+select1option.codeTypeName+'</option>'
                            }
                            $select1.append(optionStr);
                            //回显数据下拉框
                            $('#equipStatuasCode').find('option[value="'+objdata.equipStatuasCode+'"]').prop('selected','selected');
                            form.render();
                        }
                    });

                }
            })

        //结算组织监听事件
        form.on('select(selectdept)', function(data){
            var indiv=$("#ctree");
            $("#ctreediv").find("input[type='text']").remove();
            $("#ctreediv").find("div").remove();
            $("#ctreediv").append(indiv);
            ctree(null,data.value);
            form.render();
        });

        function ctree(id,deptId){
            var ctreeurldata=''; //场地位置

           /* if (deptId!=undefined){
                ctreeurldata= '/limsMaterTool/LocationTree?deptId='+deptId
            }else {
                ctreeurldata='/limsMaterTool/LocationTree'
            }*/
            treeSelect.render({
                elem: '#ctree',
                data:ctreeurldata ,
                type: 'get',
                placeholder: '请选择',
                search: true,
                style: {
                    folder: {
                        enable: true
                    },
                    line: {
                        enable: true
                    }
                },
                // 点击回调3
                click: function(d){
                    // console.log($('#'+d.current.tId).parent('ul').prev().attr('title'))
                    $('input[name="positionId"]').val(d.current.id);
                    form.render()
                },
                // 加载完成后的回调函数
                success: function (d) {
                    var treeId = $('.layui-treeSelect-body').attr('id')
                    if(id){
                        treeSelect.checkNode('tree',treeId,id);
                        //console.
                    }
                }
            });
        }



        $(".checkipt").each(function() {
            if($(this).val() == 2){
                $(this).attr('checked', true);
            }
        });

    });


    // 数组对象的删除
    function deleteItem (item, list) {
        // 先遍历list里面的每一个元素，对比item与每个元素的id是否相等，再利用splice的方法删除
        for (var key in list) {
            if (list[key].equipId === item) {
                list.splice(key, 1)
            }
        }
    };
    //获取当前时间  年月日
    function nowformat() {
        var nstr = "";
        var now = new Date();
        var nyear = now.getFullYear();
        var nmonth = now.getMonth() + 1;
        var nday = now.getDate();
        if (nmonth < 10) {
            nmonth = "0" + nmonth;
        }
        if (nday < 10) {
            nday = "0" + nday;
        }
        nstr = nyear + "-" + nmonth + "-" + nday;
        return nstr;
    }
    function addData() {
        var ownerLog = objdata;
        ownerLog.deptId = $("#deptoper").find("dl dd.layui-this").attr("lay-value");
        ownerLog.equipName = $("#equipName").val();
        ownerLog.memo = $("#memo").val();
        ownerLog.equipNo = $("#equipNo").val();
        ownerLog.modelNo = $("#modelNo").val();
        ownerLog.factoryNo = $("#factoryNo").val();
        ownerLog.positionId = $("#positionId").val();
        ownerLog.manufacturer = $("#manufacturer").val();
        ownerLog.supplier = $("#supplier").val();
        ownerLog.assetsCost = $("#assetsCost").val();
        ownerLog.equipStatuasCode = $("#zicdiv").find("dl dd.layui-this").attr("lay-value");

        return ownerLog;
    }

    function addchecked() {
        var ownerLog = {};
        $(".checkipt:checked").each(function() {
            ownerLog[$(this).val()] = 1
        });
        return ownerLog;
    }

    function addjData() {
        var jsondata = layui.table.checkStatus('Settlement').data;
        return jsondata;
    }
    //将毫秒数转为yyyy-MM-dd格式时间
    function format(t) {
        if(t) return new Date(t).Format("yyyy-MM-dd");
        else return ''
    }

</script>
</body>
</html>
